#pragma once
#include "SimpleRender.h"
#include "GameObject.h"


// A piece of renderable DirectX geometry, usually attached to a gameobject3D
class GameGeometry
{
public:
	GameGeometry(void) 
	{ 
		Init(); 
	}
	virtual ~GameGeometry(void) {}

	// material this shape is made up of
	D3DMATERIAL9 Material;

	//GameObject *Parent; // pointer to my parent

	// An individual piece of geometry may have a local translation and rotation applied 
	D3DXVECTOR3 LocalPosition;
	float LocalRotX, LocalRotY, LocalRotZ;
	float LocalScale;

	virtual void Init()
	{
		LocalPosition = D3DXVECTOR3(0,0,0);
		LocalRotX = 0;
		LocalRotY = 0;
		LocalRotZ = 0;
		LocalScale = 1;

		// init the material
		ZeroMemory( &Material, sizeof( D3DMATERIAL9 ) );
		Material.Specular.r = 1.0f;
		Material.Specular.g = 1.0f;
		Material.Specular.b = 1.0f;
		Material.Power = 64;

	}
	virtual void Update() {}
	virtual void Render()=0;

	void SetColor(float r, float g, float b)
	{
		SetColor(D3DXCOLOR(r,g,b,1));
	}

	virtual void SetColor(D3DXCOLOR color)
	{
		Material.Diffuse.r = color.r;
		Material.Diffuse.g = color.g;
		Material.Diffuse.b = color.b;
		Material.Diffuse.a = color.a;

		
		Material.Ambient.r = color.r;
		Material.Ambient.g = color.g;
		Material.Ambient.b = color.b;
		Material.Ambient.a = 1;
	}


	virtual D3DXMATRIXA16 GetLocalTransform()
	{
		D3DXMATRIXA16 scale, translation, rotation, transform;

		D3DXMatrixScaling(&scale,LocalScale, LocalScale, LocalScale);

		D3DXMatrixRotationYawPitchRoll(&rotation,LocalRotY,LocalRotX,LocalRotZ);

		D3DXMatrixTranslation(&translation,LocalPosition.x,LocalPosition.y,LocalPosition.z);

		transform = scale * rotation * translation;

		return transform;
	}

};